package Java测试.编码3copycopy;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Chat {
    public static void main(String[] args) throws Exception{
        Scanner scanner = new Scanner(System.in);
        Socket socket = new Socket("192.168.3.172", 8888);
        while (true){
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            BufferedWriter bw = new BufferedWriter(osw);
            String s = scanner.next();
            bw.write(s);
            bw.newLine();
            bw.flush();
            if (s.equals("bye")){
                break;
            }
            //接收数据
            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String s1 = br.readLine();
            System.out.println("接收的数据为:"+s1);
            if (s1.equals("bye")){
                break;
            }
        }
        socket.close();
    }
}
